import socket
import time
from datetime import datetime

class CommonHelper:
    def __init__(self):
        pass

    def getLocalHostIP(self):
        # 获取本地主机的 IP 地址
        hostname = socket.gethostname()
        ip_address = socket.gethostbyname(hostname)
        return ip_address

    @staticmethod
    def getDateFromMacro(date_str):
        """
        从宏定义的日期字符串中解析日期
        :param date_str: 日期字符串，格式为 "Mon DD YYYY"
        :return: 时间戳
        """
        month_names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
        month, day, year = date_str.split()
        month_num = month_names.index(month) + 1
        date = datetime(int(year), month_num, int(day))
        return int(time.mktime(date.timetuple()))